package com.example.a_java.controller;

import com.example.a_java.common.Result;
import com.example.a_java.service.RepaymentStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

/**
 * 还款统计控制器
 */
@Tag(name = "还款统计", description = "还款统计相关接口")
@RestController
@RequestMapping("/repayment/statistics")
@SecurityRequirement(name = "bearer-key")
public class RepaymentStatisticsController {

    @Autowired
    private RepaymentStatisticsService repaymentStatisticsService;

    /**
     * 获取还款统计数据
     */
    @Operation(summary = "获取还款统计数据")
    @GetMapping
    @PreAuthorize("hasAuthority('repayment:statistics:query')")
    public Result<Map<String, Object>> getStatistics(
            @Parameter(description = "开始日期") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
            @Parameter(description = "结束日期") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
            @Parameter(description = "统计类型(daily/monthly/yearly)") @RequestParam(defaultValue = "monthly") String type) {
        
        Map<String, Object> statistics = repaymentStatisticsService.getRepaymentStatistics(startDate, endDate, type);
        return Result.success(statistics);
    }
} 
